// Components/question/question.js
Component({
  /**
   * 生命周期
   */
  lifetimes: {
    ready() {

    }
  },
  /**
   * 组件的属性列表
   */
  properties: {
    index: {
      type: Number,
      value: 0
    },
    item: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    result: [],
    submitText: '下一题',
    cls: 'fal'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.setData({
        result: event.detail.sort(),
      })
      this.judgeRorF()
      this.uploadStatus()
    },
    minusQues() {
      this.triggerEvent('minusQues', {
        answer: this.data.result,
        cls: this.data.cls
      })
      this.judgeSubmitText()
      this.clearArr()
    },
    plusQues() {
      if(this.properties.index == 49){
        this.triggerEvent('submit')
        return
      }
      this.triggerEvent('plusQues', {
        answer: this.data.result,
        cls: this.data.cls
      })
      this.clearArr()
      this.judgeSubmitText()
    },
    judgeSubmitText() {
      let idx = this.properties.index
      this.setData({
        submitText: idx > 48 ? '提交' : '下一题'
      })
    },
    judgeRorF() {
      let answer = this.data.result;
      if (JSON.parse(this.properties.item.answers).join(',') == answer.join(',')) {
        this.setData({
          cls: 'right'
        })
      }
      if (!answer.length) {
        this.setData({
          cls: 'future'
        })
      }
    },
    clearArr() {
      if (this.properties.item.ansArr) {
        this.setData({
          result: this.properties.item.ansArr
        })
      } else {
        this.setData({
          result: []
        })
      }
    },
    uploadStatus(){
      this.triggerEvent('keepStatus',{answer:this.data.result,cls:this.data.cls})
    },
  }
})